﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using System.Data.SqlClient;

namespace DAL
{
    public class RemarkService
    {
        //评论表 
        public bool add(Remark remark)
        {
            string sql = string.Format("insert remark values('{0}','{1}','{2}','{3}','{4}')",
                remark.Username,remark.Datenow,remark.Cont,remark.Userid,remark.Proid);
            return DBhelper.ex(sql);
        }
        public SqlDataReader remarkcount(int id)
        {
            string sql = "select count(*) from remark where proid=" + id;
            return DBhelper.DataReader(sql);
        }
        public SqlDataReader getpro(Remark remark)
        {
            string sql = string.Format("select * from remark where proid='{0}'",remark.Proid);
            return DBhelper.DataReader(sql);
        }
        public SqlDataReader getuser(Remark remark)
        {
            string sql = string.Format("select * from remark where userid='{0}'", remark.Userid);
            return DBhelper.DataReader(sql);
        }
        public SqlDataReader getbyid(int id)
        {
            string sql = "select  p.Pic,r.Cont,p.ProName from product p join remark r on p.id=r.Proid join [User] u on u.Id=r.UserID where u.id=" + id;
            return DBhelper.DataReader(sql);
        }
        public SqlDataReader getbypro(int id)
        {
            string sql = "select  r.Cont,r.datenow ,u.uid from [User] u join remark r on u.id=r.userid join product p on p.Id=r.Proid where p.id=" + id;
            return DBhelper.DataReader(sql);
        }
    }
}
